package com.example.demo1.controller;

import java.beans.BeanProperty;

import javax.validation.Valid;

import com.example.demo1.model.Category;
import com.example.demo1.requestModel.categoriesReq;
import com.example.demo1.response.Response;
import com.example.demo1.service.CategoryService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "${basePath}/categories")
public class CategoriesController {

    @Autowired
    CategoryService CategoryService;

    @PostMapping("/addCategory")
    public Response addCategory(@Valid @RequestBody categoriesReq categoryRes) {

        // Category c;
        // @BeanProperty( c,categoryRes);

        CategoryService.addCategory(categoryRes);
        return Response.success();
    }

    @GetMapping(value = "/getAll")
    public Response getAll() {
        return Response.success(CategoryService.getAllCategory());
    }

}
